#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <time.h>

//#define SERVER_IP "192.168.180.1"
//#define SERVER_IP "10.220.53.143"
#define SERVER_IP "192.168.43.37"
#define SERVER_PORT 8080

void send_udp_packet(int sockfd, const unsigned char *data, size_t size) {
    struct sockaddr_in server_addr;
    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
    server_addr.sin_port = htons(SERVER_PORT);

    ssize_t sent_bytes = sendto(sockfd, data, size, 0, (struct sockaddr*)&server_addr, sizeof(server_addr));
    if (sent_bytes == -1) {
        perror("sendto");
        close(sockfd);
        exit(EXIT_FAILURE);
    }

}

int main() {
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd == -1) {
        perror("socket");
        exit(EXIT_FAILURE);
    }

    unsigned char data1[] = {0x01, 0x02, 0x04, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c};

    
    while (1) {        
        send_udp_packet(sockfd, data1, sizeof(data1));
        usleep(500000);
    } 
    close(sockfd);
    return 0;
}
